package com.cienet.playandrecord;

import mypackage.EchoScreen;

public class BufferManaer
{
    private static final int mBufferCount = 1024;
    
    private static byte[][] mBuffers = new byte[mBufferCount][];
    
    private static int mOut = 0;
    
    public static byte[] mDate;
    
    private static int mIn = 0;
    
    public static void setRecordBuffer(byte[] b)
    {
        mBuffers[getOut()] = b;
    }
    
    public static byte[] getPlayBuffer()
    {
        return mBuffers[getIn()];
    }
    
    private static int getOut()
    {
        if (mOut >= mBufferCount)
        {
            mOut = 0;
        }
        EchoScreen.log("mOut:" + mOut);
        return ++mOut;
    }
    
    private static int getIn()
    {
        if (mIn > mOut && mIn - 800 > mOut)
        {
            mIn--;
        }
        
        if (mIn >= mBufferCount)
        {
            mIn = 0;
        }
        EchoScreen.log("mIn:" + mIn);
        return ++mIn;
    }
    
    
}
